import { useQuery } from "@apollo/react-hooks";
import gql from "graphql-tag";

export const SYS_MENU = gql`
  query SysMenu {
    sysMenu {
      name
      description
      path
      children {
        name
        description
        path
      }
    }
  }
`;

export const useMenu = () => {
  const { data } = useQuery(SYS_MENU);
  const menu = [
    {
      title: "控制台",
      icon: "home",
      key: "/",
      link: "/"
    },
    {
      title: "系统管理",
      icon: "database",
      key: "/sys",
      auth: "AUTH_SYS",
      children: [
        {
          title: "用户管理",
          key: "/sys/user",
          link: "/sys/user",
          auth: "AUTH_SYS_USER"
        },
        {
          title: "角色管理",
          key: "/sys/role",
          link: "/sys/role",
          auth: "AUTH_SYS_ROLE"
        },
        {
          title: "权限管理",
          key: "/sys/authority",
          link: "/sys/authority",
          auth: "AUTH_SYS_AUTHORITY"
        }
      ]
    }
  ];
  return {
    menu: (data && data.sysMenu) || []
  };
};
